package com.baichuan.zntx.handler;

import com.baichuan.zntx.domain.LoraMessage;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class LoraJsonEncoder extends MessageToByteEncoder<LoraMessage> {
    private final ObjectMapper objectMapper = new ObjectMapper();
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, LoraMessage loraMessage, ByteBuf byteBuf) throws Exception {
        byte[] jsonBytes = objectMapper.writeValueAsBytes(loraMessage);
        byteBuf.writeBytes(jsonBytes);
    }
}
